package com.southwind.phone_store_demo.service.impl;

import com.southwind.phone_store_demo.dto.UserDTO;
import com.southwind.phone_store_demo.entity.BuyerAddress;
import com.southwind.phone_store_demo.entity.User;
import com.southwind.phone_store_demo.form.UserForm;
import com.southwind.phone_store_demo.repository.UserRepsoitory;
import com.southwind.phone_store_demo.service.UserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceInmpl implements UserService {
    @Autowired
    private UserRepsoitory userRepsoitory;

    @Override
    public void register(UserDTO userDTO) {
        User user;
        user = new User();
        user.setPassword(userDTO.getPassword());
        user.setUsername(userDTO.getUsername());
        System.out.println(userDTO.getEmail());
        user.setEmail(userDTO.getEmail());
        userRepsoitory.save(user);
    }
    private static String getType(Object a) {
        return a.getClass().toString();

    }

    @Override
    public Boolean queryByUsername(String username, String password) {
        User user = userRepsoitory.findByUsername(username);
       
        if(user!=null){
            if(user.getPassword().equals(password)){
                return true;
            }else {
                return false;
            }
        }else {
            return false;
        }

    }
}
